package com.atguigu.edu.excel;

import com.alibaba.excel.EasyExcel;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class ExcelMethods {

    private static List<DemoData> getList() {
        List<DemoData> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            DemoData demoData = new DemoData();
            demoData.setSno(""+i);
            demoData.setSname("jiajia"+i);
            list.add(demoData);
        }
        return list;
    }
    // EasyExcel 写入操作
    @Test
    public void testWrite() {
        // 写入的文件的路径
        String fileName = "C:\\Users\\qiao\\Desktop\\write.xlsx";

        EasyExcel.write(fileName,DemoData.class).sheet("学生列表").doWrite(getList());
    }

    // EasyExcel 读操作
    @Test
    public void testRead() {
        // 写入的文件的路径
        String fileName = "C:\\Users\\qiao\\Desktop\\write.xlsx";

        EasyExcel.read(fileName,DemoData.class,new ExcelListener()).sheet().doRead();
    }



}
